package temp;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;


import com.ma.R;


public class SuperFrameLayout extends FrameLayout {

    public View  mainLayout;
    public TempView tempLayout;


    public Integer getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
        tempLayout.setType(state);
        tempLayout.setVisibility(state != 0 ? VISIBLE : GONE);
        mainLayout.setVisibility(state == 0 ? VISIBLE : GONE);
    }

    private Integer state;
    TypedArray a;

    private void init(Context context, AttributeSet attrs, int defStyleAttr) {
        a = getContext().obtainStyledAttributes(attrs, R.styleable.SuperFrameLayout, defStyleAttr, 0);
        state = a.getInteger(R.styleable.SuperFrameLayout_state, 0);
        mainLayout = (View) getChildAt(0);
        if (mainLayout == null) {
            mainLayout = new LinearLayout(context);
            mainLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
            addView(mainLayout);
        }

        tempLayout = new TempView(context);
        tempLayout.setType(state);
        addView(tempLayout);
        tempLayout.setVisibility(state != 0 ? VISIBLE : GONE);
        mainLayout.setVisibility(state == 0 ? VISIBLE : GONE);
        a.recycle();

    }

    public TempView.OnTempBtClickListener getTempBtClickListener() {
        return tempBtClickListener;
    }

    public void setTempBtClickListener(TempView.OnTempBtClickListener tempBtClickListener) {
        this.tempBtClickListener = tempBtClickListener;
        tempLayout.setBtListener(tempBtClickListener);

    }

  TempView.OnTempBtClickListener tempBtClickListener;

    public SuperFrameLayout(Context context) {
        super(context);
        init(context, null, 0);
    }

    public SuperFrameLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs, 0);
    }

    public SuperFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs, defStyleAttr);
    }


}
